package com.wanxi.servlet;

import com.wanxi.model.CompanyModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.NewsModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/company")
public class CompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端数据
//        3.封装对象
//        4.调用逻辑层
        CompanyService companyService = new CompanyService();
        CompanyModel companyModel = companyService.findModel();

        NavService navService=new NavService();
        List<NavModel> navModelList=navService.findNavModelList();

//        5.返回给前端
        req.setAttribute("companyModel", companyModel);
        req.setAttribute("navModelList", navModelList);

        req.getRequestDispatcher("/jsp/company.jsp").forward(req, resp);

    }
}
